package com.FrameWork.Synchoronization;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.HandlerThread;

public class SyncReceiver extends BroadcastReceiver {
	
	private Context myContext;
	public static String SYNC_INCREMENT = "Sync.Increment";
	private Handler syncHandler;
	private Runnable syncRunnable;
	private String Category = null;
	@Override
	public void onReceive(Context context, Intent intent) {
		this.myContext = context;
		final Synchronization sync = new Synchronization(context);
		
		String action = intent.getAction();
		if("SMS".equals(intent.getStringExtra("FLAG")))
		{
			Category="SMS";
			
		}
		else
		{
			Category= null;
		}
		if (SYNC_INCREMENT.equals(action)) {//Sync.Increment
			
			HandlerThread syncThread = new HandlerThread("mySync");
			syncThread.start();
			
			syncRunnable = new Runnable() {
				
				@Override
				public void run() {
					
					if(!false){
						sync.StartSynchronization(myContext);		
					}else {
						syncHandler.postDelayed(syncRunnable, 3000);
					}
				}
			};
			
			
			syncHandler = new Handler(syncThread.getLooper());
			syncHandler.post(syncRunnable);
			
		}
	}
	
}
